package com.report.service.impl;

import cn.hutool.core.collection.ListUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.report.entity.SpecialReport;
import com.report.mapper.SpecialReportMapper;
import com.report.service.SpecialReportService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author summer
 * @version 1.0
 * @date 2024/7/20 18:53
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class SpecialReportServiceImpl extends ServiceImpl<SpecialReportMapper, SpecialReport> implements SpecialReportService {

    @Override
    public void saveSpecialReport(Integer id, List<Integer> reportIds) {
        LambdaQueryWrapper<SpecialReport> eq = Wrappers.lambdaQuery(SpecialReport.class).eq(SpecialReport::getSpecialId, id);
        this.remove(eq);
        List<SpecialReport> list= ListUtil.list(true);
        reportIds.forEach(reportId->{
            SpecialReport specialReport = new SpecialReport();
            specialReport.setSpecialId(id);
            specialReport.setReportId(reportId);
            list.add(specialReport);
        });
        this.saveBatch(list);

    }
}
